﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace isky.web
{
    /// <summary>
    /// Retransmit 的摘要说明
    /// </summary>
    public class Retransmit : IHttpHandler
    {

        string orgName;
        string SNCRMDBConnectionString;

        public Retransmit()
        {
            SNCRMDBConnectionString = ConfigurationManager.ConnectionStrings["SNCRMDBConnectionString"].ConnectionString;
        }

        public void ProcessRequest(HttpContext context)
        {
            string RecId = context.Request.QueryString["id"];
            orgName = context.Request.QueryString["orgname"];
            string entityName = context.Request.QueryString["typename"];

            if (entityName == "new_ygcb")
            {
                SqlConnection sqlconn = null;
                SqlCommand cmd = null;
                try
                {
                    sqlconn = new SqlConnection(SNCRMDBConnectionString);
                    sqlconn.Open();
                    cmd = new SqlCommand();
                    cmd.Connection = sqlconn;
                    cmd.CommandText = "SyncYgcbRetransmit";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@YGCBId", SqlDbType.UniqueIdentifier).Value = Guid.Parse(RecId);
                    int row = cmd.ExecuteNonQuery();
                    context.Response.Write("ok");
                }
                catch (Exception ex)
                {
                    context.Response.Write(string.Format("同步报价利润时发生错误-{0}", ex.Message));
                }
                finally
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                    if (sqlconn != null)
                    {
                        sqlconn.Close();
                    }
                }
            }
            else
            {
                context.Response.Write("同步报价利润时参数发生错误");
            }

        }



        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}